﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RunningCalculator
{
    public class Utility
    {
        //把待计算的距离按照显示间隔和配速段设置，分成若干距离间隙,每段距离间隙参考配速段设置进行数据计算.
        public struct DistanceGap
        {
            public double GapBeginning;
            public double GapEnd;
        };

        public struct SectionSetting
        {
            public DistanceGap Section;
            public double Pace;
        };

        //作为Dictionary key 
        public enum GapCheckedStatus
        {
            Radio_1km_Checked,
            Radio_2km_Checked,
            Radio_3km_Checked,
            Radio_4km_Checked,
            Radio_5km_Checked,
            Radio_6km_Checked,
            Radio_7km_Checked,
            Radio_8km_Checked,
            Radio_9km_Checked,
            Radio_HalfMarathon_Checked,
            Radio_Marathon_Checked
        }

        public static string ConvertSecondsToHourMinuteSecond(uint seconds, bool justForPace = false)
        {
            uint hours = seconds / 3600;
            uint minutes = (seconds % 3600) / 60;
            uint secs = seconds % 60;

            if (hours > 0 || !justForPace)
                return string.Format("{0:00}:{1:00}:{2:00}", hours, minutes, secs);
            else if(minutes > 0)
                return string.Format("{0:0}'{1:00}''", minutes, secs);
            else 
                return string.Format("{0:0}''", secs);
        }

        public static string ConvertDoubleToStr(double val)
        {
            string valueAsString = val.ToString("0.000000");

            int indexOfDecimalPoint = valueAsString.IndexOf('.');
            if (indexOfDecimalPoint == -1)
            {
                return val.ToString("0.00");
            }
            else
            {
                string decimalPart = valueAsString.Substring(indexOfDecimalPoint + 1).TrimEnd('0');
                if (decimalPart.Length < 2)
                    return val.ToString("0.00");
                else
                    return Math.Round(val, decimalPart.Length).ToString();

            }
        }
    }
}
